﻿using Microsoft.Extensions.DependencyInjection;
using Modules.BankSpecialAccount.Entitys;
using Modules.BankSpecialAccount.Repositories;
using PmSoft;

namespace Modules.BankSpecialAccount;

/// <summary>
/// 专户代发批次表服务
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class BankSpecialAccountBatchService
{
    private readonly BankSpecialAccountBatchRepository projectSpecialAccountBatchRepository;

    public BankSpecialAccountBatchService(BankSpecialAccountBatchRepository projectSpecialAccountBatchRepository)
    {
        this.projectSpecialAccountBatchRepository = projectSpecialAccountBatchRepository;
    }

    /// <summary>
    /// 专户代发批次表表单详情
    /// </summary>
    /// <param name="id">主键</param>
    /// <returns></returns>
    public BankSpecialAccountBatchInfo? Get(int id)
    {
        return projectSpecialAccountBatchRepository.Get(id);
    }

    /// <summary>
    /// 批量删除，根据id
    /// </summary>
    /// <param name="ids">id的集合</param>
    public void Deleted(IEnumerable<int> ids)
    {
        foreach (int id in ids)
        {
            Delete(id);
        }
    }

    /// <summary>
    /// 单个删除
    /// </summary>
    /// <param name="id">主键</param>
    public void Delete(int id)
    {
        projectSpecialAccountBatchRepository.DeleteByEntityId(id);
    }

    /// <summary>
    /// 创建专户代发批次表
    /// </summary>
    /// <param name="entity">实体对象</param>
    public void Create(BankSpecialAccountBatchInfo entity)
    {
        projectSpecialAccountBatchRepository.Insert(entity);
    }

    /// <summary>
    /// 编辑专户代发批次表
    /// </summary>
    /// <param name="entity">实体对象</param>
    public void Update(BankSpecialAccountBatchInfo entity)
    {
        projectSpecialAccountBatchRepository.Update(entity);
    }

    /// <summary>
    /// 是否存在对应的代发批次
    /// </summary>
    /// <param name="bankAccount"></param>
    /// <param name="batchSerial"></param>
    /// <returns></returns>
    public bool ExistBatchDetail(string bankAccount, string batchSerial)
    {
        return projectSpecialAccountBatchRepository.ExistBatchDetail(bankAccount, batchSerial);
    }
}